package com.mes.cloud.config;


import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.core.JdbcTemplate;
import javax.sql.DataSource;

@Configuration
public class DataSourceConfig {
    private static final String MASTER_MAPPER_LOCAL = "classpath:mybatis/mapper/*.xml";
    private static final String MASTER_MYBATIS_LOCAL = "classpath:mybatis/mybatis-config.xml";

    @Bean(name = "gengenDataSource")
    @Primary
    @ConfigurationProperties(prefix="spring.datasource.gengen")
    public DataSource gengenDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean(name = "gengenCrmBaseDataSource")
    @ConfigurationProperties(prefix="spring.datasource.gengenCrmBase")
    public DataSource gengenCrmBaseDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean(name = "gengenCrmCustomerDataSource")
    @ConfigurationProperties(prefix="spring.datasource.gengenCrmCustomer")
    public DataSource gengenCrmCustomerDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean(name = "gengenCrmDictDataSource")
    @ConfigurationProperties(prefix="spring.datasource.gengenCrmDict")
    public DataSource gengenCrmDictDataSource() {
        return DataSourceBuilder.create().build();
    }


    @Bean(name = "gengenJdbcTemplate")
    @Primary
    public JdbcTemplate gengenJdbcTemplate(
            @Qualifier("gengenDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

    @Bean(name = "gengenCrmBaseJdbcTemplate")
    public JdbcTemplate gengenCrmBaseJdbcTemplate(
            @Qualifier("gengenCrmBaseDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

    @Bean(name = "gengenCrmCustomerJdbcTemplate")
    public JdbcTemplate gengenCrmCustomerJdbcTemplate(
            @Qualifier("gengenCrmCustomerDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

    @Bean(name = "gengenCrmDictJdbcTemplate")
    public JdbcTemplate gengenCrmDictJdbcTemplate(
            @Qualifier("gengenCrmDictDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }



}
